package com.zy.web.controllers;

import com.zy.web.bean.ResponseResult;
import lombok.extern.java.Log;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

/**
 * @program: shopping153_cloud
 * @description: spring mvc 的controller类的全局异常处理
 * @author: zy
 * @create: 2025-08-20 14:56
 */
@ControllerAdvice
@Log
public class GlobalExceptionHandler {

    //TODO: 处理自定义异常


    @ExceptionHandler(Exception.class)
    public ResponseEntity<ResponseResult> handleAllException(Exception ex) {
        ex.printStackTrace();
        log.severe( "全局异常处理:"+ ex.getMessage() );
        // 自定义异常处理逻辑
        return new ResponseEntity<>( ResponseResult.error("产品服务模块致命错误:" + ex.getMessage()), HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
